
const app = getApp();
const regeneratorRuntime = global.regeneratorRuntime = require('../libs/regenerator');
const co = require("../libs/co");
const http = require('../libs/httpRequest');
const appConfig = require('../appConfig');

var DataService = function () {
    var _getRichContent = function *(richId) {
        var ret = yield http.request({
            url: `${appConfig.api.baseUrl}/data/richContent`,
            data: {richId:richId},
            method: 'POST',
            success: (res) => {
                console.log(res.data);
            },
            fail: (err) => {
                console.log(err);
            }
        });
        return ret;
    }

    var _getFormKey = function *(formId) {
        var ret = yield http.request({
            url: `${appConfig.api.baseUrl}/data/formKey`,
            data: {formId:formId},
            method: 'POST',
            success: (res) => {
                console.log(res.data);
            },
            fail: (err) => {
                console.log(err);
            }
        });
        return ret;
    }

    var _saveFormData = function *(formId,jsonValue) {
      var ret = yield http.request({
          url: `${appConfig.api.baseUrl}/data/saveForm`,
          data: {formId:formId,json:jsonValue},
          method: 'POST',
          success: (res) => {
              console.log(res.data);
          },
          fail: (err) => {
              console.log(err);
          }
      });
      return ret.apiStatus.statusCode;
    }

    return {
        getRichContent: _getRichContent,
        getFormKey: _getFormKey,
        saveFormData: _saveFormData
    }
}();

module.exports = DataService;
